#include "mysqlserver.h"

mysqlServer::mysqlServer() {

    this->UID = "UID=root;";
    this->PWD = "PWD=761449091..;";
    this->DATABASE = "DATABASE=kdcserver;";
    this->PORT = "PORT=3306";
    this->SERVER = "SERVER=127.0.0.1;";
    this->DRIVER = "DRIVER={MySQL ODBC 8.0 Unicode Driver};";

}
bool mysqlServer::connectMysql()
{
    QString tmp;
    // 加载 QODBC 驱动
    this->db = QSqlDatabase::addDatabase("QODBC");
    tmp = this->DRIVER + this->SERVER + this->DATABASE + this->UID + this->PWD + this->PORT;
    qDebug() << (tmp); // 测试打印
    db.setDatabaseName(tmp); // 设置要连接的数据库名称
    return db.open(); // 尝试简历连接成功返回真，失败返回假
}

mysqlServer::~mysqlServer()
{
    db.close(); // 关闭连接
}
